<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "/xadmin/inc/common.html">
<script type="text/javascript">
	var grid;
	$(function() {
		//分类管理表格  
		grid = $('#deptgrid').treegrid({
        idField:'id',    
    	treeField:'name',
    	//parentField:'fid',
        url:'deptmanage-listdept',  
        loadMsg:'数据加载中请稍后……',  
        striped: true,  
        pagination: true,  
        rownumbers: true, 
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
        columns:[[ 
         	 {field:'id',title: 'ID',align: 'center',width: '100'},
         	 {field : 'name',title : '部门名称',align: 'left',width : '200'}, 
             {field:'fname',title: '上级部门',align: 'center',width: '200'},
             {field:'px',title: '排序',align: 'center',width: '100'},
             {field:'zt',title: '操作',align: 'center',width: '100',
             	formatter: function(value,rowdata,index){
             		var str = '';
					if(value ==0){
						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong('+rowdata.id+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-no l-btn-icon-left">启用</span></span></a>';
					}else{
						str += '<a id="btnstate" class="l-btn l-btn-plain" href="javascript:jinyong('+rowdata.id+','+rowdata.zt+')"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">禁用</span></span></a>';
					}
					return str;
             	}
             }  
         ]],
         toolbar : [btn_add,btn_edit,btn_del,"-"] 
      });
    });
   //新增部门
	function doAdd() {
		var url = '${request.contextPath}/xadmin/system/deptmanage-deptwindow';
		top.modalwindow(url, grid, {width:500, height:230, title:'新增部门信息'});
	}
	//修改部门
	function doEdit() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		//
		var url = '${request.contextPath}/xadmin/system/deptmanage-deptwindow?id='+selected.id;
		top.modalwindow(url, grid, {width:500, height:230,title:'修改部门信息'});
	}
	//删除部门
	function doDel(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("deptmanage-deldept", {"id":selected.id},function(data) {
					grid.treegrid('reload');
				   	top.messagershow(data);			   	
				});
			}
		});
	}
	//
	function jinyong(id,result){
		if(result==0){
			result = 1;
		}else{
			result = 0;
		}
		$.post("deptmanage-updatedeptzt", {"id":id, "zt":result},	function(data){
				grid.treegrid('reload'); 
		   		top.messagershow(data);
			}
		);
	}
</script>

</head>
<body>
	<table id="deptgrid" data-options="fit:true,border:false"></table>
</body>
</html>